﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

namespace Reflect
{
    class Program
    {
        static void Main(string[] args)
        {

            //动态加载DLL，这个LoadFile最方便，参数就是dll的路径。
            Assembly asm = Assembly.LoadFile(@"D:\0Code\ECAPP\DxyAutoProject\DesignPattern\ClassLibrary\bin\Debug\ClassLibrary.dll");
            //获取Student类的类型
            Type type = asm.GetType("ClassLibrary.Student");
            //创建该类的实例
            Object instance = asm.CreateInstance("ClassLibrary.Student");
            //为学生类的属性赋值
            type.GetProperty("name").SetValue(instance, "段天涯", null);
            type.GetProperty("age").SetValue(instance, 18, null);
            //获取Student类的方法
            var method = type.GetMethod("Hello");
            //调用Student类的成员方法Hello
            method.Invoke(instance, null);
            Console.Read();
        }
    }
}
